/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pl.cezary.butler.walili.server;

import pl.cezary.butler.walili.common.Task;
import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

/**
 *
 * @author Cezary Butler
 */
public class DelayedServerTask implements Delayed {

    private int delay; //opoznienie w sekundach
    private Task zad;

    public DelayedServerTask(Task z, int d, TimeUnit u) {
        zad = z;
        delay = (int) TimeUnit.SECONDS.convert(d, u);
    }

    public DelayedServerTask(Task z, int d) {
        delay = d*60;
        zad = z;
    }
    
    public Task getZadanie(){
        return zad;
    }
    
    public ServerTask getZadanieSerwer(){
        return ServerTask.getZadanieSerwer(zad);
    }

    public long getDelay(TimeUnit tu) {
        return tu.convert(delay, TimeUnit.MINUTES);
    }

    public int compareTo(Delayed arg0) {
        if(arg0 instanceof DelayedServerTask)
            return delay-((DelayedServerTask)arg0).delay;
        else 
            return (int) (getDelay(TimeUnit.SECONDS) - arg0.getDelay(TimeUnit.SECONDS));
    }
}
